package cn.myeasyai.util;


/**
 * 操作结果
 *
 * @author fushoujiang
 */

public class Result<T> {

    /**
     * 是否成功
     */
    private boolean success;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回结果
     */
    private T data;
    /**
     * 响应码
     */
    private int code;

    public Result(boolean success , int code, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
        this.code = code;
    }

    public Result() {
        //默认无参构造
    }

    /**
     * 通用失败返回
     * @param <T> 结果实体
     * @return 通用失败返回
     */
    public static <T> Result<T> resultFail(int code,String message){
        Result<T> crmOperateResult = new Result<>();
        crmOperateResult.setSuccess(Boolean.FALSE);
        crmOperateResult.setCode(code);
        crmOperateResult.setMessage(message);
        return crmOperateResult;
    }
    /**
     * 通用成功返回
     * @param <T> 结果实体
     * @return 通用失败返回
     */
    public static <T> Result<T> resultSuccess(T date,String message){
        Result<T> crmOperateResult = new Result<>();
        crmOperateResult.setSuccess(Boolean.TRUE);
        crmOperateResult.setCode(0);
        crmOperateResult.setMessage(message);
        crmOperateResult.setData(date);
        return crmOperateResult;
    }
    /**
     * 通用成功返回
     * @param <T> 结果实体
     * @return 通用失败返回
     */
    public static <T> Result<T> resultSuccess(T date ){
        return resultSuccess(date,"成功");
    }


    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}
